package com.itheima.health.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.health.entity.PageResult;
import com.itheima.health.entity.QueryPageBean;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.Permission;
import com.itheima.health.service.PermissionService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author:ZZZ
 * @Date: 2021/1/19 10:36
 * @Version 1.0
 */
@RestController
@RequestMapping("/permission")
public class PermissionController {

    @Reference
    PermissionService permissionService;

    @RequestMapping("/add")
    public Result add(@RequestBody Permission permission){
        permissionService.add(permission);
        return new Result(true, "新增权限成功");
    }

    @RequestMapping("/deleteById")
    public Result deleteById(int id){
        System.out.print("啦啦啦");
    }

    @RequestMapping("/findPage")
    public Result findPage(@RequestBody QueryPageBean queryPageBean) {
       PageResult<Permission> pageResult= permissionService.findPage(queryPageBean);
        return new Result(true, "分组骚骚骚骚骚功",pageResult);
    }

    @RequestMapping("/update")
    public Result update(@RequestBody Permission permission){
        permissionService.update(permission);
        return new Result(true, "修改权限成功");
    }


    @RequestMapping("/findById")
    public Result findById(int id){
        Permission permission=permissionService.findById(id);
        return new Result(true, "按id查询权限成功",permission);
    }

    /**
     * 查询所有权限
     * @return
     */
    @GetMapping("/findPermissionAll")
    public Result findPermissionAll(){
        List<Permission> permissionList = permissionService.findPermissionAll();
        return new Result(true,"查询角色成功",permissionList);

    }

}
